package com.carrot.gateway.util;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * @description:加密工具
 * @author: zl
 * @date: 2023/10/19
 */
public class CryptoUtil {


    /**
     * RSA参数解密
     * @param encryptedData
     * @param privateKey
     * @return
     */
    public static Object rsaDecrypt(String encryptedData,String privateKey){
        RSA rsa=new RSA(privateKey,null);
        byte[] decryptedData = rsa.decrypt(encryptedData, KeyType.PrivateKey);
        String  decryptedString = new String(decryptedData);
        return decryptedString;
    }


    public static Object rsaEncrypt(String data,String publicKey){
        RSA rsa=new RSA(publicKey,null);
        byte[] decryptedData = rsa.encrypt(data, KeyType.PublicKey);
        String  decryptedString = new String(decryptedData);
        return decryptedString;
    }

}
